﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpeedMultByTimeFactor : EffectFactorBase
{
	protected float duration;
	protected float speedAffect;

	protected float time;

	public SpeedMultByTimeFactor(float _duration, float _affect)
	{
		this.duration = _duration;
		this.speedAffect = _affect;
		time = 0;
		Factor = "SpeedMutiByTimeFactor";
	}

	public override void EndEffect(RoleAtrEntity role)
	{
		base.EndEffect(role);
		if (speedAffect > 1)
			role.SpeedMultiPos /= speedAffect;
		else
			role.SpeedMultiNeg /= speedAffect;
	}

	public override void StartEffect(RoleAtrEntity role)
	{
		base.StartEffect(role);
		if (speedAffect > 1)
			role.SpeedMultiPos *= speedAffect;
		else
			role.SpeedMultiNeg *= speedAffect;
	}

	public override void Tick(RoleAtrEntity role, float deltaTime)
	{
		base.Tick(role, deltaTime);
		time += deltaTime;
		if (time >= duration)
		{
			role.RemoveFactor(this);
		}
	}

	public override void ReFresh()
	{
		base.ReFresh();
		time = 0;
	}
}
